﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WXYW.Entities;
using WXYW.DAL;

namespace WXYW.BLL
{
    public class DropDownItemService : RepositoryBase
    {
        public List<DropDownItem> GetAllChargeReason()
        {
            return GetEntities<DropDownItem>().Where(s => s.Type == "ChargeReason").ToList();
        }

        public List<DropDownItem> GetAllReceiptType()
        {
            return GetEntities<DropDownItem>().Where(s => s.Type == "ReceiptType").ToList();
        }

        public DropDownItem GetDropDownItemByID(int ID)
        {
            return GetEntities<DropDownItem>(p => p.ID == ID).FirstOrDefault();
        }

        public bool IsDuplicateByUpdateName(string newName, int updateID)
        {
            return GetEntities<DropDownItem>(p => p.Name == newName && p.ID != updateID).Count() > 0;
        }

        public void UpdateName(string newName, int updateID)
        {
            DropDownItem dropDownItem = GetDropDownItemByID(updateID);
            dropDownItem.Name = newName;
            UpdateEntity(dropDownItem);
        }

        public void AddChargeReason(DropDownItem dropDownItem)
        {
            dropDownItem.Type = "ChargeReason";
            InsertEntity(dropDownItem);
        }

        public void AddReceiptType(DropDownItem dropDownItem)
        {
            dropDownItem.Type = "ReceiptType";
            InsertEntity(dropDownItem);
        }

        public void DeleteDropDownItemByID(int ID)
        {
            DeleteEntities<DropDownItem>(s => s.ID == ID, Guid.Empty);
        }
    }
}
